package com.py.behavior.servicer.impl;

import com.py.apis.article.IArticleClient;
import com.py.behavior.servicer.BhLikesService;
import com.py.model.behavior.dtos.LikesBehaviorDto;
import com.py.model.common.dtos.ResponseResult;
import com.py.model.common.enums.AppHttpCodeEnum;
import com.py.utils.common.ApUserThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName BhLikesServiceImpl
 * @Description TODO
 * @Author AXing
 * @Date 2022/11/16 13:22
 * @Version 1.0
 */
@Service
@Slf4j
public class BhLikesServiceImpl implements BhLikesService {

    @Autowired
    private IArticleClient  articleClient;

    /**
     * 文章点赞
     * @param dto
     * @return
     */
    @Override
    public ResponseResult likeBehavior(LikesBehaviorDto dto) {
        //当前用户id
        Integer userId = ApUserThreadLocalUtil.get().getId();
        dto.setUserId(userId);
        log.info("likeBehavior·······>likesBehaviorDto: {}", dto);
        if (dto == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        if (dto.getType() == 0){
            //文章点赞
            log.info("文章点赞");
            Integer articleLikes = articleClient.articleLikes(dto);
            log.info("点赞数量：{}", articleLikes);
            if (articleLikes == null){
                return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
            }
            return ResponseResult.okResult(articleLikes);
        } else if (dto.getType() == 1){
            //TODO：动态点赞
            return null;
        } else{
            //TODO：评论点赞
            return null;
        }
    }
}
